package com.qf.service.Impl;

import com.qf.dto.ResultCode;
import com.qf.exceptions.AddDataException;
import com.qf.mapper.CategoryMapper;
import com.qf.pojo.Categories;
import com.qf.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
    private CategoryMapper categoryMapper;
    @Autowired
    public void setCategoryMapper(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public List<Categories> findAllCategory() {
        return categoryMapper.selectAllCategory();
    }

    @Override
    public void addcategory(String categoryName) {
        if (categoryName == null ) {
            //数据不符合我们的要求,返回结果,中断操作,抛出异常
            throw new AddDataException("分类名称不能为空", ResultCode.NULL_CATEGORYNAME);
        }
        categoryMapper.addcategory(categoryName);
    }
}
